package reflectPracticeDemo;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.DateFormat.Field;

public class reflectDemo {

	public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, SecurityException,
			InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchFieldException {
		//Class<Student> c1 = Student.class;
//		System.out.println(c1);

//		Student s = new Student();
//		Class<? extends Student> c2 = s.getClass();
//		System.out.println(c2 == c1);

//带三个参数的构造方法
//		Class<Student> c1 = Student.class;
//		Constructor<?> cons3 = c1.getDeclaredConstructor(int.class, String.class, int.class);
//
//		var instance3 = cons3.newInstance(22, "周杰伦", 1);
//		System.out.println(instance3);

//带一个参数的构造方法,暴力反射
//		Class<Student> c1 = Student.class;
//		Constructor<?> cons1 = c1.getDeclaredConstructor(String.class);
//		cons1.setAccessible(true);
//		var Instance1 = cons1.newInstance("陈冠希");
//		System.out.println(Instance1);

		
//使用指定的成员变量 age
		Class<Student> c1 = Student.class;				
		Constructor<Student> con_age = c1.getDeclaredConstructor();
		Student s = con_age.newInstance();
		
//成员变量可以在创建的时候赋值，也可以在后边获得成员变量后通过set赋值		
//		Constructor<Student> con_age = c1.getDeclaredConstructor(int.class);
//		con_age.setAccessible(true);
//		Student s = con_age.newInstance(11);
		
//		java.lang.reflect.Field ageField = c1.getField("age");
//		ageField.set(s, 11);
		
		System.out.println(s);
	}

}
